<#assign pojo=oneToManyPojo.getOne()>
<#assign many=oneToManyPojo.getMany()>
<#assign ones=oneToManyPojo.getOnes()>
package ${pojo.getPackageName()}.dao;

<#assign classbody>
	<#assign service="${pojo.getDeclarationNameFirstLetterLower()}Service">
<#assign declarationName = pojo.importType(pojo.getDeclarationName())>
	<#assign declarationNameFirstLetterLower = "${pojo.getDeclarationNameFirstLetterLower()}">
	<#assign declarationComment = "${pojo.getComment()}">
/**
 * @author bo.wang
 */
public class Base${declarationName}Dao extends BaseDao{

	public static final String BEAN_ID="${pojo.getDeclarationNameFirstLetterLower()}Dao";

	protected void build${declarationName}Query(StringBuffer query,Map values,Map params) {
		query.append(" from ${declarationName} where 1=1 ");
		Object value=params.get("flag");
		if(AssertHelper.notEmpty(value))
		{
			query.append(" and flag=:flag");
			values.put("flag", value);
		}else{
			query.append(" and flag=:flag");
			values.put("flag", TableColnumDef.FLAG_EFFECT);
		}
		if(AssertHelper.notEmpty(TableColnumDef.FILTER_NAME_PATTERN))
		{
			//			query.append(" and status=:status");
			//			values.put("status", value);
		}
	}
	<#assign parentid = pojo.getDeclarationNameFirstLetterLower()+"Id">
	<#foreach child in many>
		<#assign childdeclarationName = child.importType(child.getDeclarationName())>
	protected void build${childdeclarationName}Query(StringBuffer query,Map values,Map params) {
		query.append(" from ${childdeclarationName} where 1=1 ");
		Object value=params.get("${parentid}");
		if(AssertHelper.notEmpty(value))
		{
			value=value.toString();
			query.append(" and ${parentid}=:${parentid}");
			values.put("${parentid}", value);
		}
		value=params.get("flag");
		if(AssertHelper.notEmpty(value))
		{
			query.append(" and flag=:flag");
			values.put("flag", value);
		}else{
			query.append(" and flag=:flag");
			values.put("flag", TableColnumDef.FLAG_EFFECT);
		}
		if(AssertHelper.notEmpty(TableColnumDef.FILTER_NAME_PATTERN))
		{
//			query.append(" and status=:status");
//			values.put("status", value);
		}
	}
	</#foreach>
	<#foreach child in ones>
		<#assign childdeclarationName = child.importType(child.getDeclarationName())>
	protected void build${childdeclarationName}Query(StringBuffer query,Map values,Map params) {
		query.append(" from ${childdeclarationName} where 1=1 ");
		Object value=params.get("${parentid}");
		AssertHelper.notEmpty_assert("${childdeclarationName}关联主键不能为空");
		if(AssertHelper.notEmpty(value))
		{
			value=value.toString();
			query.append(" and ${parentid}=:${parentid}");
			values.put("${parentid}", value);
		}
		value=params.get("flag");
		if(AssertHelper.notEmpty(value))
		{
			query.append(" and flag=:flag");
			values.put("flag", value);
		}else{
			query.append(" and flag=:flag");
			values.put("flag", TableColnumDef.FLAG_EFFECT);
		}
	}
	</#foreach>

	public DaoPage find${declarationName}ByParams(Map params, Integer pageIndex,Integer pageSize)
	{
		StringBuffer query=new StringBuffer();
		Map values=new HashMap();
		build${declarationName}Query(query, values, params);
		return pageBy(query, values, pageIndex, pageSize);
	}
	public List<${declarationName}> find${declarationName}ByParams(Map params)
	{
		StringBuffer query=new StringBuffer();
		Map values=new HashMap();
		build${declarationName}Query(query, values, params);
		return findBy(query, values);
	}
<#assign parentid = pojo.getDeclarationNameFirstLetterLower()+"Id">
<#foreach child in many>
<#assign childdeclarationName = child.importType(child.getDeclarationName())>
	public DaoPage find${childdeclarationName}ByParams(Map params, Integer pageIndex,Integer pageSize)
	{
		StringBuffer query=new StringBuffer();
		Map values=new HashMap();
		build${childdeclarationName}Query(query, values, params);
		return pageBy(query, values, pageIndex, pageSize);
	}
	public List<${childdeclarationName}> find${childdeclarationName}ByParams(Map params)
	{
		StringBuffer query=new StringBuffer();
		Map values=new HashMap();
		build${childdeclarationName}Query(query, values, params);
		return findBy(query, values);
	}
</#foreach>
<#foreach child in ones>
<#assign childdeclarationName = child.importType(child.getDeclarationName())>
	public ${childdeclarationName} find${childdeclarationName}(Map params)
	{
		StringBuffer query=new StringBuffer();
		Map values=new HashMap();
		build${childdeclarationName}Query(query, values, params);
		return (${childdeclarationName}) getFirstRecord(findBy(query, values));
	}
</#foreach>
}
</#assign>
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.ling.pl.core.commons.constant.TableColnumDef;
import com.ling.pl.core.commons.support.DaoPage;
import com.ling.pl.core.commons.utils.AssertHelper;
import com.ling.pl.core.dao.impl.BaseDao;
import ${pojo.getModelPackageName()}.${declarationName};
import ${pojo.getModelPackageName()}.${declarationName};
import ${pojo.getPackageName()}.dao.${declarationName}Dao;
<#foreach child in ones>
<#assign childdeclarationName = child.importType(child.getDeclarationName())>	
import ${child.getPackageName()}.model.${childdeclarationName};
import ${child.getPackageName()}.model.${childdeclarationName};
</#foreach>
<#foreach child in many>
<#assign childdeclarationName = child.importType(child.getDeclarationName())>	
import ${child.getPackageName()}.model.${childdeclarationName};
import ${child.getPackageName()}.model.${childdeclarationName};
</#foreach>
${classbody}
